package api

import (
	"github.com/labstack/echo/v4"
	global2 "longmen/server/config/global"
	"longmen/server/internal/services/consumers/publisher"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/helper/util"
)

// @Summary 检查维护状态
// @Description 检查维护状态
// @Accept  json
// @Produce  json
// @Tags SYS
// @Param   sendBody body api_models.MaintainReq true "body"
// @Success 200 {object} api_models.MaintainResp "result"
// @Router /api/maintain [POST]
func (base *Controller) Maintain(c echo.Context) error {
	//res := &api_models.MaintainResp{}
	//return util.BuildSuccess(c, res, "")
	req := &api_models.MaintainReq{}
	if err := util.Json2Struct(c.Get("body").(string), req); err != nil {
		return util.BadParam(c, err)
	}
	resp, err := base.Service.Maintain(req.Device)
	if err != nil {
		return util.BuildFail(c, 1, "", err)
	}
	// 推送使用统计
	err = global2.PublisherStatistic.StatisticPush(
		publisher.UsageStatistic, base.GetAuthUserId(c), base.GetDeviceInfo(c), c.RealIP(), base.GetPlatform(c),
	)
	if err != nil {
		global2.Log.Infof("stats error: %v", err)
	}
	return util.BuildSuccess(c, resp, "")
}
